# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=aarch64 -o - -run-pass=early-tailduplication -verify-machineinstrs %s | FileCheck %s

# Reproducer for a problem found with an out-of-tree target. This being
# an attempt to re-create that for an in-tree target.
#
# When tail duplicator is duplicating the $s1 assignment into
# bb.0 it need to resolve both the subreg access in the PHI
# and the subreg access in the COPY.
#
# So what we expect is to find some thing like
#   $s1 = COPY %0.dsub_then_ssub
# with two levels of subreg accesses (possibly composed into one subreg index).


---
name:            foo2
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: foo2
  ; CHECK: bb.0.entry:
  ; CHECK-NEXT:   successors: %bb.4(0x80000000)
  ; CHECK-NEXT:   liveins: $q1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:fpr128 = COPY $q1
  ; CHECK-NEXT:   $s1 = COPY [[COPY]].ssub
  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:fpr64 = COPY [[COPY]].dsub
  ; CHECK-NEXT:   B %bb.4
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.4(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:fpr128 = IMPLICIT_DEF
  ; CHECK-NEXT:   $s1 = COPY [[DEF]].ssub
  ; CHECK-NEXT:   [[COPY2:%[0-9]+]]:fpr64 = COPY [[DEF]].dsub
  ; CHECK-NEXT:   B %bb.4
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   B %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.4:
  ; CHECK-NEXT:   successors: %bb.4(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   B %bb.4
  bb.0.entry:
    liveins: $q1

    %0:fpr128 = COPY $q1
    B %bb.2

  bb.1:
    %1:fpr128 = IMPLICIT_DEF
    B %bb.2

  bb.2:
    %2:fpr64 = PHI %0.dsub, %bb.0, %1.dsub, %bb.1
    $s1 = COPY %2.ssub
    B %bb.4

  bb.3:
    B %bb.3

  bb.4:
    B %bb.4
...

